package com.yunhe.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.yunhe.bean.Task;
import com.yunhe.iservice.TaskPostIService;

/**
 * 任务管理模块
 * 
 * 处理任务的发布，任务列表等
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/task")
public class TaskPostController {
    
    //private static Logger logger=LogManager.getLogger(TaskPostController.class);

    // 注入任务发布服务接口
    @Autowired
    private TaskPostIService taskPostIService;

    /**
     * 任务发布页面跳转方法
     * 
     * 处理html页面转向ftl模板页面
     * 
     * @param string taskType
     *              任务类型
     * @return
     *        ftl模板页面，并携带任务类型参数
     */
    @RequestMapping("/taskPostHandler")
    public ModelAndView taskPostHandler(String taskType) {
        //logger.info("taskType: "+taskType);
        System.out.println("taskType: "+taskType);
        
        return null;
    }
    /**
     * 根据taskId查询出对应的任务信息 ，并在前台页面展示
     * 
     * @param taskId
     * @param request
     * @param response
     * @return 任务信息 task集合
     */
    @RequestMapping("/taskshow")
	@ResponseBody
	public List<Task> taskshow(Integer taskId,HttpServletRequest request,HttpServletResponse response){
		/*String tid = request.getParameter("taskId");
		System.out.println(tid);
		Integer taskId = Integer.valueOf(tid);
		System.out.println(taskId);*/
    	System.out.println(taskId);
		List<Task> t=taskPostIService.getTaskById(taskId);
		System.out.println(t);
		return t;
	}
	
    /**
     *  
     *  根据创建时间查询出不同领域的任务信息，并把数据传给前台展示
     *  
     * @param skill
     * @param request
     * @param response
     * 
     * @return task集合
     */
    @RequestMapping("/skillCreate")
	@ResponseBody
	public List<Task> getTaskByCreate(String skill,HttpServletRequest request,HttpServletResponse response){
    	System.out.println(skill);
		List<Task> skillCreate = taskPostIService.getTaskByCreate(skill);
		System.out.println(skillCreate);
		return skillCreate;
    	/*List<Task> skillCreate = taskPostIService.getTaskByCreate("金融");
    	return skillCreate;*/
	}
    
    /**
     * 把所有的任务信息查出并传输给前台页面展示
     * 
     * @param request
     * @param response
     * @return task集合
     * 
     * 
     */
    @RequestMapping("/skillCount")
   	@ResponseBody
   	public List<Task> getTaskByCount(HttpServletRequest request,HttpServletResponse response){
   		List<Task> skillCount = taskPostIService.getTaskByCount();
   		return skillCount;
   	}

}
